<template>
  <div class="adaddress">
    <van-row>
      <van-col span="24">
        <van-nav-bar
          title="地址编辑"
          left-text="返回"
          left-arrow
          @click-left="onClickLeft"
        />
      </van-col>
    </van-row>
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
import { addPosition } from "../../api/address";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
    };
  },
  computed: {},
  watch: {},

  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    async onSave(content) {
      console.log(content);
      console.log(content.name);
      const result = await addPosition({
        recerver: content.name,
        mobile: content.tel,
        regions: content.province - content.city - content.county,
        address: content.addressDetail,
        idDefault: content.isDefault,
      });
      console.log("result", result);
      console.log(result.code);
      if (result.code == "success") {
        this.$router.push("/address/");
      }
      Toast("save");
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
  created() {},
  mounted() {},
  components: {},
};
</script>
<style scoped>
</style>